<template>
	<view><baseForm :column="column" @submitFun="submitFun"></baseForm></view>
</template>

<script>
import baseForm from '@/wxcomponents/form/form.vue';
import login from '@/libs/login.js';
export default {
	data() {
		return {
			column: [
				{
					label: '申请人',
					name: 'name',
					type: 'normalInput',
					disabled: true,
					value: '',
					check: {
						checkType: 'string',
						checkRule: '1,3',
						errorMsg: '请输入姓名'
					}
				},
				{
					label: '企业名称',
					name: 'enterpriseName',
					type: 'normalInput',
					disabled: true,
					value: '',
					check: {
						checkType: 'string',
						checkRule: '1,3',
						errorMsg: '请输入姓名'
					}
				},
				{
					label: '企业联系人',
					name: 'enterpriseContact',
					type: 'normalInput',
					disabled: true,
					value: '',
					check: {
						checkType: 'string',
						checkRule: '1,3',
						errorMsg: '请输入姓名'
					}
				},
				{
					label: '企业联系人电话',
					name: 'enterprisePhone',
					type: 'normalInput',
					disabled: true,
					value: '',
					check: {
						checkType: 'string',
						checkRule: '1,3',
						errorMsg: '请输入姓名'
					}
				},
				{
					label: '所在省市',
					name: 'enterpriseAreaCity',
					type: 'normalInput',
					disabled: true,
					value: '',
					check: {
						checkType: 'string',
						checkRule: '1,3',
						errorMsg: '请输入姓名'
					}
				},
				{
					label: '企业地址',
					name: 'enterpriseAddress',
					type: 'normalInput',
					disabled: true,
					value: '',
					check: {
						checkType: 'string',
						checkRule: '1,3',
						errorMsg: '请输入姓名'
					}
				},
				{
					label: '实习负责人',
					name: 'practicePrincipal',
					type: 'normalInput',
					disabled: true,
					value: '',
					check: {
						checkType: 'string',
						checkRule: '1,3',
						errorMsg: '请输入姓名'
					}
				},
				{
					label: '实习负责人电话',
					name: 'practicePrincipalPhone',
					type: 'normalInput',
					disabled: true,
					value: '',
					check: {
						checkType: 'string',
						checkRule: '1,3',
						errorMsg: '请输入姓名'
					}
				},
				{
					label: '实习时间',
					name: 'practiceTime',
					type: 'normalInput',
					disabled: true,
					value: '',
					check: {
						checkType: 'string',
						checkRule: '1,3',
						errorMsg: '请输入姓名'
					}
				}
			],

			params: {}
		};
	},
	async onLoad(option) {
		let companyInfo = JSON.parse(option.data);
		let user = await login.getStorage('user');
		this.setColumn(user);
		this.setColumn(companyInfo);
		this.setColumnTime(companyInfo);
		
		this.params = {
			practiceEnterpriseName: companyInfo.enterpriseName,
			studentNumber: user.number,
			practiceEnterpriseId: companyInfo.id
		};
	},
	methods: {
		submitFun(e) {
			this.$http
				.post({
					url: '/enrollment/practiceApply/save',
					data: this.params
				})
				.then(e => {
					this.showToast('提交成功',()=> {uni.navigateBack()});
				})
				.catch(e => {
					uni.showToast({
						title: '信息提交失败',
						icon: 'none'
					});
				});
		},
		setColumn(data) {
			this.column.forEach(item => {
				if (data[item.name]) {
					item.value = data[item.name];
				}
			});
		},
		setColumnTime(data) {
			this.column.forEach(item => {
				if (item.name == 'practiceTime') {
					item.value = data.practiceStartTime.split(' ')[0] + '至' + data.practiceEndTime.split(' ')[0];
				}
			});
		},
		filterData(data) {
			let params = {};
			data.forEach(item => {
				// let ele= {}
				// let name = item.name
				// let value = item.value
				// ele[item.name] = item.value
				// console.log(ele)
				// params=  Object.assign(ele, params)
			});
			return params;
		}
	},
	components: {
		baseForm
	}
};
</script>

<style lang="scss" scoped></style>
